import axios from 'axios'
import {Message, MessageBox} from 'element-ui'
import Vue from 'vue'
import store from '@/store'
import fa from "element-ui/src/locale/lang/fa";

// create an axios instance
const service = axios.create({
    baseURL: '/api', // url = base url + request url
    // withCredentials: true, // send cookies when cross-domain requests
    timeout: 50000 // request timeout
})

// 请求拦截器
service.interceptors.request.use(
    config => {
        // do something before request is sent
        config.headers["Content-Type"] = "application/json";
        config.headers['token'] = Vue.ls.get("token");
        return config
    },
    error => {
        // do something with request error
        console.log(error) // for debug
        return Promise.reject(error)
    }
)
let show = false;
// 响应拦截器
service.interceptors.response.use(
    response => {
        // console.log(response, "response.data")
        return response.data;
    },
    error => {
        console.log('err',error)
        Message({
            message: error.message,
            type: 'error',
            duration: 5 * 1000
        })
        return Promise.reject(error)
    }
)

export default service
